import isPrime from "./isPrime";
export class NumberTimer {
  timer;
  constructor(duration = 500, currNum = 1) {
    this.duration = duration;
    this.currNum = currNum;
    this.onNumberCreated = null; // 当数字产生时，调用的回调函数
    this.timer = null;
  }
  start() {
    if (this.timer) return;
    this.timer = setInterval(() => {
      this.onNumberCreated?.(this.currNum, isPrime(this.currNum));
      this.currNum++;
    }, this.duration);
  }
  stop() {
    clearInterval(this.timer);
    this.timer = null;
  }
}
